const app = getApp();
// 声明变量
import {
  IMSDK,
} from '../utils/common';
Component({
  data: {
    selected: 1,
    Sum_: Number,
    list: [{
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_tab_nor.png",
        "selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_tab_select.png",
        'isCode': false
      },
      {
        "pagePath": "/pages/dynamic/dynamic", 
        "text": "动态",
        "iconPath":"https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_dongtai_tab_nor.png",
        "selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_dongtai_tab_select.png",
        'isCode': false
      },
      { 
        "pagePath": "/pages/message/message",
        "text": "消息",
        "iconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_news_tab_nor.png",
        "selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_news_tab_select.png",
        'isCode': false
      },
      {
        "pagePath": "/pages/my_home/my_home",
        "text": "我的",
        "iconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_my_tab_nor.png",
        "selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_my_tab_select.png",
        'isCode': false
      }
    ],
    "color": "#898D92",
    "selectedColor": "#323437",
    //适配IphoneX的屏幕底部横线
    isIphoneX: app.globalData.isIphoneX,
  },
  attached() { 
     let tim =  IMSDK(this) 
    //  console.log(app.globalData.Sum_);
    //  console.log(tim);
    this.setData({ 
      Sum_:app.globalData.Sum_
    })
  },  

  methods: {
    tab_icon(e) {
      if (e == 1) {
        this.setData({
          "list[0].isCode": true,
          "list[0].selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_top_icon.png"
        })
      } else {
        this.setData({
          "list[0].isCode": false,
          "list[0].selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_tab_select.png"
        })
      }
    },
    BackTop() {
      wx.pageScrollTo({
        scrollTop: 0
      })
      this.setData({
        "list[0].isCode": false,
        "list[0].selectedIconPath": "https://img.xunyinjiaoyou.com/static/xiaochengxu/imageapple523/home_tab_select.png"
      })
    },
    switchTab(e) {
      const dataset = e.currentTarget.dataset
      const path = dataset.path
      const index = dataset.index
      console.log(dataset);
      //如果是特殊跳转界面
      if (this.data.list[index].pagePath) {
        wx.switchTab({
          url: path
        })
        this.setData({
          selected: index
        })
      }
    }
  }
})
